// 头像信息界面

cc.Class({
    extends: cc.Component,

    properties: {
        m_name:'',
        m_id:'',
        m_ip:'',
        m_addressLayout:null,
    },

    onLoad () {
        var BGNode = this.node.getChildByName("BGNode");
        
        // 信息
        var InfoLayout = BGNode.getChildByName("InfoLayout");

        // 名字
        this.m_name = InfoLayout.getChildByName("NameLayout");
        // ID
        this.m_id = InfoLayout.getChildByName("IDLayout");
        // IP
        this.m_ip = InfoLayout.getChildByName("IPLayout");
        // 地址
        this.m_addressLayout = InfoLayout.getChildByName("AddressLayout");
    },

    // 名字
    SetName : function(str) {
        if(str && str.length > 0) {
            this.m_name.getChildByName("nameLabel").getComponent(cc.Label).string = str;
        } else {
            this.m_name.active = false;
        }
    },

    // ID
    SetID : function(id) {
        if(id  && id.length > 0) {
            this.m_id.getChildByName("ID").getComponent(cc.Label).string = id;
        } else {
            this.m_id.active = false;
        }
    },

    // IP
    SetIP : function(ip) {
        if(ip && ip.length > 0) {
            this.m_ip.getChildByName("IP").getComponent(cc.Label).string = ip;
        } else {
            this.m_ip.active = false;
        }
    },

    // 地址
    SetAddRess : function(address) {
        if(address && address.length > 0) {
            this.m_addressLayout.getChildByName("Address").getComponent(cc.Label).string = address;

            // 设置框图的高度
            this.m_addressLayout.height = 50 * (this.m_addressLayout.getChildByName("Address").height/40);
        } else {
            this.m_addressLayout.active = false;
        }
    },

    // 头像设置
    SetIcon : function(str) {
        var sprite = this.node.getChildByName("BGNode").getChildByName("IconNode").getChildByName("IconMask").getChildByName("Icon").getComponent(cc.Sprite);
        var realUrl = cc.url.raw('resources/Communal/4.png');
        cc.loader.load(realUrl, function (err, texture) {
            var frame = new cc.SpriteFrame(texture);
            sprite.spriteFrame = frame;
            sprite.node.width = 150;
            sprite.node.height = 150;
        });
    },

    // 设置界面显示内容
    SetIconInfo : function(data) {
        this.SetIcon('');

        this.SetName('');

        this.SetID('');

        this.SetIP('');

        this.SetAddRess('');
    },
});
